package com.hongxun.modules.bss.service.impl;

import java.util.UUID;

import com.hongxun.modules.bss.entity.RemoveEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.dao.DDeviceOldDao;
import com.hongxun.modules.bss.entity.DDeviceOldEntity;
import com.hongxun.modules.bss.service.DDeviceOldService;



@Service("dDeviceOldService")
public class DDeviceOldServiceImpl implements DDeviceOldService {
	@Autowired
	private DDeviceOldDao dDeviceOldDao;

	@Override
	public DDeviceOldEntity queryObject(String guid){
		return dDeviceOldDao.queryObject(guid);
	}
	
	@Override
	public List<DDeviceOldEntity> queryList(Map<String, Object> map){
		return dDeviceOldDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return dDeviceOldDao.queryTotal(map);
	}
	
	@Override
	public void save(DDeviceOldEntity dDeviceOld){
        if(dDeviceOld.getGuid()==null||dDeviceOld.getGuid().equals("")) {

		    dDeviceOld.setGuid(UUID.randomUUID().toString());
        }
		dDeviceOldDao.save(dDeviceOld);
	}
	
	@Override
	public void update(DDeviceOldEntity dDeviceOld){
		dDeviceOldDao.update(dDeviceOld);
	}
	
	@Override
	public void delete(String guid){
		dDeviceOldDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		dDeviceOldDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<DDeviceOldEntity> entities) {
		for (DDeviceOldEntity d : entities) {
			if (d.getDRDatastate().equals("删除")) {
				dDeviceOldDao.delete(d.getGuid());
			} else {
				DDeviceOldEntity dDeviceOldEntity = dDeviceOldDao.queryObject(d.getGuid());
				if (dDeviceOldEntity == null) {
					dDeviceOldDao.save(d);
				} else {
					dDeviceOldDao.update(d);
				}
			}
		}
	}

	@Override
	public List<RemoveEntity> removeList(Map<String, Object> map) {
		return dDeviceOldDao.removeList(map);
	}

	@Override
	public int queryTotalForRemove(Map<String, Object> map) {
		return dDeviceOldDao.queryTotalForRemove(map);
	}
}
